import urllib.request
from urllib.request import urlretrieve
import getImage

url = "https://www.tute.edu.cn/xysh/yxtzsd/1.htm"
response = urllib.request.urlopen(url)
cc = ""
cc = response.read().decode('utf-8')
print(cc)
list1 = getImage.getImg(cc)
print("总共找到了{0}张图片".format(len(list1)))
num = int(input("请输入要下载的图片数："))
for i in range(num):
    urlretrieve(list1[i],'img{0}.jpg'.format(i))
print("下载成功")


def save_files(url,index):
    request = urllib.request.Request(url)
    request.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36')
    response = urllib.request.urlopen(request)
    img = response.read()

    with open('tute_' + str(index) + '.jpg' , 'wb') as f:
        f.write(img)
    print('图片'+str(index)+"存储成功！")

save_files(list1[7],7)